const App = getApp();
import {
    url
} from '../../modelApi/url_config.js'
Page({
    data: {
        ifuserFlag: false,
        isphoneFlag: false,
        checked: true,
        stopBtn: false,
        ischeckFlag: true,
        backPage: ""
    },
    onLoad() {
        if (!App.globalData.isShow) {
            wx.redirectTo({
                url: "/pages/errorPage/index"
            });
            return
        }
    },
    onShow() {
        this.setData({
            backPage: wx.getStorageSync('backPage')
        })
        wx.removeStorageSync('backPage')
        if (wx.getStorageSync('accessToken')) {
            this.setData({
                ifuserFlag: true
            })
        } else if (wx.getStorageSync('tel')) {
            this.setData({
                isphoneFlag: true
            })
        }
    },
    /* 获取手机号 */
    getPhoneNumber: function (e) {
        if (e.detail.errMsg === "getPhoneNumber:ok") {
            const param = {
                encryptedData: e.detail.encryptedData,
                iv: e.detail.iv,
            };
            App.ajax(url.wxDecodePhoneUrl, param, 'post').then(res => {
                wx.setStorageSync("tel", res.data.purePhoneNumber)
                this.setData({
                    isphoneFlag: true
                })
                wx.reLaunch({
                    url:  this.data.backPage != ''?  this.data.backPage : '/pages/mine/index',
                })
            })
        }
    },
    /* 用户授权按钮事件 */
    bindgetuserinfo(e) {
        App.ifLogin(() => {
            this.setData({
                ifuserFlag: true
            })
        })
    },
    notget() {
        wx.reLaunch({
            url: '/pages/index/index',
        })
    },
    close() {
        this.setData({
            stopBtn: false
        })
    },
    open() {
        this.setData({
            stopBtn: true
        })
    },
    checkboxChange(e) {
        this.setData({
            ischeckFlag: Object.prototype.toString.call(e.detail.value).slice(8,-1) === 'Array' && e.detail.value.length > 0
        })
    },
    usrTIS() {
        wx.showToast({
          title: '请先勾选用户协议',
          icon: 'none',
          duration: 1000
        })
    }
})